<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <!-- <view class="jtop_l" @tap="navigateBack">关闭</view> -->
      <view class="jtop_c">待办</view>
      <view class="jtop_r" @tap="to_add"
        ><image src="../../static/img/doc/ic_add.png"></image
      ></view>
    </view>
    <view class="tophr"></view>

    <!-- <view class="doc_bs" v-if="!nodata"> -->
    <view class="doc_bs">
      <view
        class="doc_b"
        @longpress="logoTime(item.id)"
        v-for="(item, index) in items"
        :key="item.id"
      >
        <image
          src="../../static/img/doc/ic_check_normal@2x.png"
          class="doc_bl"
          @tap="dwc(item.id)"
        ></image>
        <view class="doc_b2" @tap="xxq(item.id, item)">
          <text class="doc_b2t">{{ item.content }}</text>
          <text class="doc_b2f"
            >提醒我：{{ item.reminderTime ? item.reminderTime : '无' }}
          </text>
        </view>
      </view>

      <view class="nd" v-if="ittems.length > 0">
        <view class="nd_bt" @tap="ck" v-if="!xs">
          <text>显示已完成事项</text>
          <image src="../../static/img/x.png"></image>
        </view>
        <view class="nd_bt" @tap="yc" v-if="xs">
          <text>隐藏已完成事项</text>
          <image src="../../static/img/s.png"></image>
        </view>
      </view>

      <view v-if="xs">
        <view class="doc_b" v-for="(item, index) in ittems" :key="item.id">
          <image
            src="../../static/img/doc/ic_check_press@2x.png"
            class="doc_bl"
            @tap="dwc2(item.id)"
          ></image>
          <view class="doc_b2 doc_b22" @tap="xxq2(item.id, item)">
            <text class="doc_b2t">{{ item.content }}</text>
            <text class="doc_b2f">提醒我：{{ item.reminderTime }} </text>
          </view>
        </view>
      </view>

      <!-- 无内容 -->
      <view class="no" v-if="nodata && ittems.length == 0 && items.length == 0">
        <view class="no_t">
          <image src="../../static/img/index/2/ic_backlog_grey.png"></image>
        </view>
        <view class="no_c">
          暂无待办
        </view>
        <view class="no_f" @tap="to_add">
          新建一个待办
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_jrename: false,
      ashowpop_jdel: false,
      ashowpopT: false,
      bj: false,
      yd: false,

      curDate: '',
      markDays: [],
      collapsible: false,
      nian: '',
      yue: '',
      nodata: false,
      items: [],
      ittems: [],
      jqeditid: '',
      ashowpop2: false,
      projectId: uni.getStorageSync('dqfull_name').id,
      xs: false,
    };
  },
  onShow() {
    this.lb();
    uni.setStorageSync('jqeditry', []);
  },
  methods: {
    xxq(e, i) {
      console.log(e, i);
      uni.setStorageSync('jc', i);

      // uni.setStorageSync("jqeditry",["9f33519b2709d196", "2d480471f21417e3"])

      if (i.participants.length > 0) {
        uni.setStorageSync('jqeditry', i.participants);
      }
      uni.navigateTo({
        url: '../main/need_edit',
      });
    },

    xxq2(e, i) {
      console.log(e, i);
      uni.setStorageSync('jc', i);

      // uni.setStorageSync("jqeditry",["9f33519b2709d196", "2d480471f21417e3"])

      if (i.participants.length > 0) {
        uni.setStorageSync('jqeditry', i.participants);
      }
      uni.navigateTo({
        url: '../main/need_more',
      });
    },

    dwc(e) {
      // 获取列表信息
      request({
        url: `/msg/todo-list/change-complete/${e}`,
        method: 'PUT',

        success: res => {
          if (res.data.success == true) {
            this.lb();
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    dwc2(e) {
      // 获取列表信息
      request({
        url: `/msg/todo-list/change-complete/${e}`,
        method: 'PUT',

        success: res => {
          if (res.data.success == true) {
            this.lb();
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    lb(e) {
      // 获取列表信息
      request({
        url: `/msg/todo-list/list`,
        method: 'GET',
        data: {
          page: 1,
          size: 1000,
          complete: true,
        },

        success: res => {
          console.log('项目dd列表11', res.data.data);
          // console.log(res.data.data.length);

          if (res.data.success == true) {
            if (res.data.data) {
              this.ittems = res.data.data;
            } else {
              this.ittems = '';
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });

      // 获取列表信息
      request({
        url: `/msg/todo-list/list`,
        method: 'GET',
        data: {
          page: 1,
          size: 1000,
          complete: false,
        },

        success: res => {
          console.log('项目列表', res);
          // console.log(res.data.data.length);
          if (res.data.success == true) {
            // console.log('1111:', res.data.data.length);
            if (res.data.data) {
              this.items = res.data.data;
              console.log(this.items);
              this.nodata = false;
            } else {
              this.items = '';
              this.dqfull_name = '';
              this.nodata = true;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    logoTime(e) {
      var that = this;
      console.log(e);

      uni.showModal({
        title: '删除',
        content: '确定要删除吗？',
        success: function(res) {
          if (res.confirm) {
            request({
              url: `/msg/todo-list/${e}`,

              method: 'DELETE',
              success: openIdRes => {
                console.log(openIdRes);
                if (openIdRes.data.success == true) {
                  wx.showToast({
                    title: '删除成功',
                    icon: 'none',
                    duration: 800,
                    success: function() {
                      setTimeout(function() {
                        that.lb();
                      }, 500);
                    },
                  });

                  // uni.navigateBack()
                } else {
                  this.repeat_click = true;
                  uni.showToast({
                    title: openIdRes.data.msg,
                    icon: 'none',
                  });
                  that.isLoading = false;
                }
              },
              fail: () => {
                this.repeat_click = true;
                uni.showToast({
                  title: '服务器开小差，请稍后~',
                  icon: 'none',
                });
                return false;
              },
            });
          }
        },
      });
    },

    ck() {
      this.xs = true;
    },
    yc() {
      this.xs = false;
    },
    // 跳转
    to_add() {
      uni.setStorageSync('jqeditry', []);

      uni.navigateTo({
        url: '../main/need_add',
      });
    },

    navigateBack() {
      uni.switchTab({
        url: '/pages/main/main',
      });
      // uni.navigateBack();
    },
  },
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}

.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 400rpx 0 0;
}
.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}
.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}
.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}
.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}
.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

.doc_bs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
}
.doc_b {
  width: 720rpx;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
  margin: 0 0 0 30rpx;
}
/* .doc_bs .doc_b:last-child{ border: 0;} */
.doc_bl {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 36rpx 0;
}
.doc_bt {
  width: auto;
  height: 42rpx;
  line-height: 42rpx;
  font-size: 34rpx;
  display: block;
  float: left;
  color: #000000;
  margin: 37rpx 0 0 0;
}
.doc_br {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 32rpx 0;
}
.doc_b2 {
  width: 600rpx;
  height: auto;
  display: block;
  float: left;
}
.doc_b2t {
  width: 600rpx;
  height: auto;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
  margin: 18rpx 0 10rpx;
  display: block;
  float: left;
}
.doc_b2f {
  width: 600rpx;
  height: auto;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #fc9422;
  margin: 0rpx 0 rpx;
  display: block;
  float: left;
}

.index {
  background: #ffffff;
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}

.doc_b22 {
  opacity: 0.5;
}

.nd {
  width: 735rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0 0 0rpx;
}
.nd_bt {
  width: auto;
  height: 48rpx;
  display: table;
  float: none;
  border: 1px solid #dddddd;
  border-radius: 24rpx;
  margin: 40rpx auto 30rpx;
}
.nd_bt text {
  width: auto;
  height: 48rpx;
  display: block;
  float: left;
  margin: 0 7rpx 0 18rpx;
  line-height: 48rpx;
  color: #666666;
  font-size: 24rpx;
}
.nd_bt image {
  width: 13rpx;
  height: 8rpx;
  display: block;
  float: left;
  margin: 21rpx 14rpx 0 0;
}
</style>
